﻿using System.Configuration;
using System.Data.SqlClient;


namespace WebShopData
{
    public static class DB
    {
        public static string ConnectionString
        {
            get
            {
                string connectionString = ConfigurationManager.ConnectionStrings["theDB"].ToString();
                var newConnectionString = new SqlConnectionStringBuilder(connectionString);
                newConnectionString.ApplicationName = ApplicationName ?? newConnectionString.ApplicationName;
                newConnectionString.ConnectTimeout = (ConnectionTimeOut > 0)
                    ? ConnectionTimeOut
                    : newConnectionString.ConnectTimeout;
                return newConnectionString.ToString();
            }
        }
        public static int ConnectionTimeOut { get; set; }
        public static string ApplicationName { get; set; }
        public static SqlConnection GetConnection()
        {
            var conn = new SqlConnection(ConnectionString);
            conn.Open();
            return conn;
        }
    }
}
